<template>
	<view class="page-content" style="background: url(../../static/sex/bg.png);background-size: 100%  100%;">
		<view style="color: #333333;font-size: 36rpx;padding: 150rpx 0 150rpx 10%;">
			<!-- {{ item.describe }} -->
			选择性别
		</view>
		<view>
			<view class="flex" style="display: flex;justify-content: space-between;align-items: center">
				<view @click="select(index)" v-for="(item, index) in 2"
					style="width: 180px;height: 180px;padding: 20px;position: relative;display: flex;flex-direction: column;align-items: center;">
					<image style="width: 100%;height: 100%;" class="avatar"
						:src="index === 0 ? '../../static/sex/woman.png' : '../../static/sex/man.png'" mode=""></image>
					<image style="width: 40rpx;height: 40rpx;" class="select"
						:src="num == index ? '../../static/sex/select.png' : '../../static/sex/selected.png'" mode="">
					</image>
				</view>
			</view>
		</view>
		<!-- <image
			@click="gourl('/pages/kongjian/xuni?item=' + JSON.stringify(item) + '&sex=' + (num + 1) + '&type=' + type)"
			src="https://yunkeososyunchuc.bc8t.cn/lianaikongjian/static/button.png"
			style="width: 50%; position: fixed; z-index: 1; bottom: 80px; left: 50%; margin-left: -25%;"
			mode="widthFix"></image> -->
		<view class="btn" style="background: url(../../static/index/btn-two.png);background-size: 100%  100%;"
			@click="gourl('/pages/kongjian/xuni?item=' + JSON.stringify(item) + '&sex=' + (num + 1) + '&type=' + type)">
			邀请另一半加入
		</view>
		<view v-if="istrue" style="text-align: center;color: #fff;width: 240px;margin: auto;">
			<!-- 邀请好友 -->
			<u-button open-type="share" style="width:240px;" type="success" shape="circle">邀请好友</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: {},
				num: -1,
				istrue: false,
				my_space_id: '',
				type: '',
				spaceInfo: {}
			};
		},
		onLoad(e) {
			if (e.item) {
				this.item = JSON.parse(e.item);

				if (this.item.id) {
					this.getSpaceInfo(this.item.id);
				}

				if (!e.type) {
					this.type = e.type;
					this.getmy_space();
				}
			}
			if (e.my_space_id) {
				this.my_space_id = e.my_space_id;
				this.item.describe = '绑定空间';
			}
		},
		onShareAppMessage(res) {
			if (!this.my_space_id) {
				uni.showToast({
					title: '获取空间信息失败，请返回重试！',
					icon: 'none',
					duration: 2000
				});
				setTimeout(function() {
					uni.navigateTo({
						url: '/pages/index/index'
					});
				}, 2000);
			}
			return {
				title: '来和我一起开通吧',
				path: 'pages/kongjian/kongjian?my_space_id=' + this.my_space_id
			};
		},
		methods: {
			kongjian() {
				this.getmy_space();
			},
			getSpaceInfo(id) {
				let self = this;
				this.$u.api.space_info({
					'id': id
				}).then((res) => {
					self.spaceInfo = res;
				});
			},
			async getmy_space() {
				let res = await this.$u.api.my_space();
				// console.log(res,'4444',res[0].space_id)
				if (res.length > 0) {
					uni.navigateTo({
						url: '/pages/content/content'
					})
				}
				// this.form=res[0]
				// this.$u.vuex('vuex_user_content',this.form)
				// this.gettype(res)
				// this.allapi()
			},
			gourl(e) {
				if (this.num == -1) {
					return uni.showToast({
						title: '请选择性别',
						icon: 'none'
					});
				}
				if (this.my_space_id) {
					return this.bind(this.my_space_id, this.num + 1);
				}
				uni.navigateTo({
					url: e
				});
				// this.create(e)
			},
			select(e) {
				this.num = e;
			},
			async bind(id, sex) {
				/*if (!this.vuex_user.avatar) {
					const userInfo = await this.user();
					const user = await this.$u.api.getUserInfo(userInfo);
					this.$u.vuex('vuex_user', user);
				}*/

				let data = {
					my_space_id: id,
					sex: sex
				};
				let res = await this.$u.api.bind_my_space(data);
				uni.switchTab({
					url: '/pages/content/content'
				});
			},
			async create(e) {
				let data = {
					space_id: this.item.id,
					sex: this.num + 1
				};
				let res = await this.$u.api.create(data);
				// if(res.status==1){
				// uni.setStorageSync('my_space_id',res.my_space_id)
				this.my_space_id = res.id;
				// this.istrue=true
				// uni.switchTab({
				// 	url:e
				// })
				// }
				// this.kongjianlist=res.data
			}
		}
	};
</script>

<style scoped>
	page {
		background: #fec5ce;
	}

	.page-content {
		width: 100%;
		height: 100vh;
		background-size: cover;
	}

	.btn {
		position: absolute;
		left: 50%;
		bottom: 250rpx;
		transform: translateX(-50%);
		width: 90%;
		height: 150rpx;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
	}
</style>